home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / CW GUSI 1.6.4 / include / sys⁄fcntl.h < prev    next >
Text File  |  1995-06-15  |  8KB  |  218 lines

  1. /*-
  2.  * Copyright (c) 1983, 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)fcntl.h    5.14 (Berkeley) 7/1/91
  34.  */
  35.  
  36. #ifndef _FCNTL_H_
  37. #define    _FCNTL_H_
  38.  
  39. #ifdef __MWERKS__
  40. /*
  41.  * Metrowerks C++ 1.2.2 sometimes seems to be confused about search path order.
  42.  * Furthermore, users sometimes make mistakes, too.
  43.  */
  44. #ifdef _FCNTL
  45. #ifndef _TYPES_H_
  46. #error "Headers conflict. Please #include <sys/fcntl.h> before <fcntl.h>"
  47. #endif
  48. #else
  49. /* Prevent future inclusions of MW fcntl.h */
  50. #define _FCNTL
  51. #endif
  52. #endif
  53.  
  54. /*
  55.  * This file includes the definitions for open and fcntl
  56.  * described by POSIX for <fcntl.h>; it also includes
  57.  * related kernel definitions.
  58.  */
  59.  
  60. #ifndef KERNEL
  61. #include <sys/types.h>
  62. #endif
  63.  
  64. /*
  65.  * File status flags: these are used by open(2), fcntl(2).
  66.  * They are also used (indirectly) in the kernel file structure f_flags,
  67.  * which is a superset of the open/fcntl flags.  Open flags and f_flags
  68.  * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
  69.  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
  70.  */
  71. /* open-only flags */
  72. #ifdef __MWERKS__
  73. #define    O_RDONLY        1                /* open for reading only */
  74. #define    O_WRONLY        2                /* open for writing only */
  75. #define    O_RDWR        0                /* open for reading and writing */
  76. #define  O_APPEND        0x0100        /* open the file in append mode */
  77. #define  O_CREAT        0x0200        /* create the file if it doesn't exist */
  78. #define  O_EXCL        0x0400        /* if the file already exists don't create it again */
  79. #define  O_TRUNC        0x0800        /* truncate the file after opening it */
  80. #define  O_BINARY        0x8000        /* open the file in binary mode (default is text mode) */
  81. #else
  82. #define    O_RDONLY        0                /* open for reading only */
  83. #define    O_WRONLY        1                /* open for writing only */
  84. #define    O_RDWR        2                /* open for reading and writing */
  85. #endif
  86. #define    O_ACCMODE    0x0003        /* mask for above modes */
  87.  
  88. #ifdef KERNEL
  89. /*
  90.  * Kernel encoding of open mode; separate read and write bits
  91.  * that are independently testable: 1 greater than the above.
  92.  */
  93. #define    FREAD            0x0001
  94. #define    FWRITE        0x0002
  95. #endif
  96. #define    O_NONBLOCK    0x0004        /* no delay */
  97. #ifndef __MWERKS__
  98. #define    O_APPEND        (1<< 3)        /* set append mode */
  99. #define    O_CREAT        (1<< 8)        /* create if nonexistant */
  100. #define    O_TRUNC        (1<< 9)        /* truncate to zero length */
  101. #define    O_EXCL        (1<<10)        /* error if already exists */
  102. #endif
  103.  
  104. #ifndef _POSIX_SOURCE
  105. #define    O_SHLOCK        0x0010        /* open with shared file lock */
  106. #define    O_EXLOCK        0x0020        /* open with exclusive file lock */
  107. #define    O_ASYNC        0x0040        /* signal pgrp when data ready */
  108. #define    O_FSYNC        0x0080        /* synchronous writes */
  109. #endif
  110.  
  111. #ifdef KERNEL
  112. #define    FMARK            0x1000        /* mark during gc() */
  113. #define    FDEFER        0x2000        /* defer for next gc pass */
  114. #define    FHASLOCK        0x4000        /* descriptor holds advisory lock */
  115. #endif
  116.  
  117. /* defined by POSIX 1003.1; BSD default, so no bit required */
  118. #define    O_NOCTTY        0        /* don't assign controlling terminal */
  119.  
  120. #ifdef KERNEL
  121. /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
  122. #define    FFLAGS(oflags)    ((oflags) + 1)
  123. #define    OFLAGS(fflags)    ((fflags) - 1)
  124.  
  125. /* bits to save after open */
  126. #define    FMASK        (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  127. /* bits settable by fcntl(F_SETFL, ...) */
  128. #define    FCNTLFLAGS    (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  129. #endif
  130.  
  131. /*
  132.  * The O_* flags used to have only F* names, which were used in the kernel
  133.  * and by fcntl.  We retain the F* names for the kernel f_flags field
  134.  * and for backward compatibility for fcntl.
  135.  */
  136. #ifndef _POSIX_SOURCE
  137. #define    FAPPEND        O_APPEND    /* kernel/compat */
  138. #define    FASYNC        O_ASYNC        /* kernel/compat */
  139. #define    FFSYNC        O_FSYNC        /* kernel */
  140. #define    FNONBLOCK    O_NONBLOCK    /* kernel */
  141. #define    FNDELAY        O_NONBLOCK    /* compat */
  142. #define    O_NDELAY        O_NONBLOCK    /* compat */
  143. #endif
  144.  
  145. /*
  146.  * Constants used for fcntl(2)
  147.  */
  148.  
  149. /* command values */
  150. #define    F_DUPFD        0        /* duplicate file descriptor */
  151. #define    F_GETFD        1        /* get file descriptor flags */
  152. #define    F_SETFD        2        /* set file descriptor flags */
  153. #define    F_GETFL        3        /* get file status flags */
  154. #define    F_SETFL        4        /* set file status flags */
  155. #ifndef _POSIX_SOURCE
  156. #define    F_GETOWN    5        /* get SIGIO/SIGURG proc/pgrp */
  157. #define F_SETOWN    6        /* set SIGIO/SIGURG proc/pgrp */
  158. #endif
  159. #define    F_GETLK        7        /* get record locking information */
  160. #define    F_SETLK        8        /* set record locking information */
  161. #define    F_SETLKW    9        /* F_SETLK; wait if blocked */
  162.  
  163. /* file descriptor flags (F_GETFD, F_SETFD) */
  164. #define    FD_CLOEXEC    1        /* close-on-exec flag */
  165.  
  166. /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
  167. #define    F_RDLCK        1        /* shared or read lock */
  168. #define    F_UNLCK        2        /* unlock */
  169. #define    F_WRLCK        3        /* exclusive or write lock */
  170. #ifdef KERNEL
  171. #define    F_WAIT        0x010        /* Wait until lock is granted */
  172. #define    F_FLOCK        0x020         /* Use flock(2) semantics for lock */
  173. #define    F_POSIX        0x040         /* Use POSIX semantics for lock */
  174. #endif
  175.  
  176. /*
  177.  * Advisory file segment locking data type -
  178.  * information passed to system by user
  179.  */
  180. struct flock {
  181.     short    l_type;        /* lock type: read/write, etc. */
  182.     short    l_whence;    /* type of l_start */
  183.     off_t    l_start;    /* starting offset */
  184.     off_t    l_len;        /* len = 0 means until end of file */
  185.     pid_t    l_pid;        /* lock owner */
  186. };
  187.  
  188.  
  189. #ifndef _POSIX_SOURCE
  190. /* lock operations for flock(2) */
  191. #define    LOCK_SH        0x01        /* shared file lock */
  192. #define    LOCK_EX        0x02        /* exclusive file lock */
  193. #define    LOCK_NB        0x04        /* don't block when locking */
  194. #define    LOCK_UN        0x08        /* unlock file */
  195. #endif
  196.  
  197.  
  198. #ifndef KERNEL
  199. #include <sys/cdefs.h>
  200.  
  201. __BEGIN_DECLS
  202. #ifdef macintosh
  203. int  open(const char*, int);
  204. int  creat(const char*);
  205. int  fcntl(int, unsigned int, int);
  206. #else
  207. int    open __P((const char *, int, ...));
  208. int    creat __P((const char *, mode_t));
  209. int    fcntl __P((int, int, ...));
  210. #endif
  211. #ifndef _POSIX_SOURCE
  212. int    flock __P((int, int));
  213. #endif /* !_POSIX_SOURCE */
  214. __END_DECLS
  215. #endif
  216.  
  217. #endif /* !_FCNTL_H_ */
  218.